Programming Recommendations (PEP 8)
Comparisons to singletons like None should always be done with is or is not, never the equality operators.
「Noneのようなシングルトンの比較は常にisやis notを使ってなされるべき」
「同値性の演算子(理解:== や !=)を使ってはならない」
Also, beware of writing if x when you really mean if x is not None
「if x is not Noneを本当は意味しているのに、if xと書くこともまた注意」
e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!
「例えば、デフォルト値がNoneの変数や引数に別の値が設定されているか確認するとき」
「別の値は(コンテナのように)ブール値のコンテキストでFalseと評価される型かもしれない」
理解:空のコンテナはFalseで、NoneもFalseなので、if xではこれらが区別できない
Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier:
積ん読(以下を理解したい)
The first form means that the name of the resulting function object is specifically ‘f’ instead of the generic ‘<lambda>’. This is more useful for tracebacks and string representations in general. The use of the assignment statement eliminates the sole benefit a lambda expression can offer over an explicit def statement (i.e. that it can be embedded inside a larger expression)
Derive exceptions from Exception rather than BaseException.
When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause: